<div class="col-md-12">
<?php echo $this->Form->create('Map', array('class' => 'form-horizontal', 'type' => 'file'));?>
<div class="portlet">
	<div class="portlet-title">
		<div class="caption"> <i class="fa fa-cogs"></i><?= __('Bản đồ'); ?> </div>
		<div class="tools"> </div>
	</div>

	<div class="portlet-body">
		<div class="table-responsive clearfix">
				<div id="map"> </div>

			<div class="form-body mt20 clearfix">
				<?php echo $this->Form->hidden('Map.id' )?>
				<div class="form-group">
					<label class="col-sm-2 control-label"><?= __('Địa chỉ');?></label>
					<div class="col-sm-6">
						<?php echo $this->Form->input('Map.address', array( 'label' => false, 'div' => false, 'class' => 'form-control') )?>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label"><?= __('Thông tin khác');?></label>
					<div class="col-sm-10 mt7">
						<div class="block">
						<?php if(empty($this->data[$als])): ?>
						<div class="row item" data-sort="0">
							<div class="col-sm-1">
								<label><?= __('STT') ?></label>
								<?php echo $this->Form->input($als.'.sort', array( 'type' => 'text', 'label' => false, 'name' => 'data['.$als.'][0][sort]', 'div' => false, 'required' => 'none', 'class' => 'form-control') )?>
							</div>
							<div class="col-sm-2">
								<label><?= __('Class') ?></label>
								<?php echo $this->Form->input($als.'.class', array( 'label' => false, 'name' => 'data['.$als.'][0][class]', 'div' => false, 'required' => 'none', 'class' => 'form-control') )?>
							</div>
							<div class="col-sm-2">
								<label><?= __('Tên') ?></label>
								<?php echo $this->Form->input($als.'.name', array( 'label' => false, 'name' => 'data['.$als.'][0][name]', 'div' => false, 'required' => 'none',  'class' => 'form-control') )?>
							</div>
							<div class="col-sm-5">
								<label><?= __('Nội dung') ?></label>
								<?php echo $this->Form->input($als.'.content', array( 'label' => false, 'name' => 'data['.$als.'][0][content]', 'required' => 'none', 'div' => false, 'class' => 'form-control') )?>
							</div>
							<div class="col-sm-2 mt26">
								<a href="#" class="btn btn-sm btn-primary add"><i class="fa fa-plus icon-only"></i></a>
								<a href="#" class="btn btn-sm btn-danger hide del"><i class="fa fa-trash-o icon-only"></i></a>
							</div>
						</div>
						<?php else: ?>
						<?php $count = count($this->data[$als]); foreach($this->data[$als] as $k => $v): ?>
						<div class="row item" data-sort="<?= $k ?>">
							<div class="col-sm-1">
								<label><?= __('STT') ?></label>
								<?php echo $this->Form->input('sort', array( 'type' => 'text','value' => $v['sort'],  'label' => false, 'name' => 'data['.$als.']['.$k.'][sort]', 'div' => false, 'required' => 'none', 'class' => 'form-control'. (!empty($v['errors']['sort'][0]) ? ' form-error' : '') ) )?>
								<?php if(!empty($v['errors']['sort'][0])):?>
								<div class="error-message"><?= $v['errors']['sort'][0] ?></div>
								<?php endif; ?>
							</div>
							<div class="col-sm-2">
								<label><?= __('Class') ?></label>
								<?php echo $this->Form->input('class', array( 'label' => false, 'value' => $v['class'],  'name' => 'data['.$als.']['.$k.'][class]', 'div' => false, 'required' => 'none', 'class' => 'form-control') )?>
							</div>
							<div class="col-sm-2">
								<label><?= __('Tên') ?></label>
								<?php echo $this->Form->input('name', array( 'label' => false, 'value' => $v['name'],  'name' => 'data['.$als.']['.$k.'][name]', 'div' => false, 'required' => 'none',  'class' => 'form-control'. (!empty($v['errors']['name'][0]) ? ' form-error' : '') ) )?>
								<?php if(!empty($v['errors']['name'][0])):?>
								<div class="error-message"><?= $v['errors']['name'][0] ?></div>
								<?php endif; ?>
							</div>
							<div class="col-sm-5">
								<label><?= __('Nội dung') ?></label>
								<?php echo $this->Form->input('content', array( 'label' => false, 'value' => $v['content'], 'name' => 'data['.$als.']['.$k.'][content]', 'required' => 'none', 'div' => false, 'class' => 'form-control'. (!empty($v['errors']['content'][0]) ? ' form-error' : '') ) )?>
								<?php if(!empty($v['errors']['content'][0])):?>
								<div class="error-message"><?= $v['errors']['content'][0] ?></div>
								<?php endif; ?>
							</div>
							<div class="col-sm-2 mt26">
								<a href="#" class="btn btn-sm btn-primary add <?= $k == ($count - 1) ? '' : 'hide' ?>"><i class="fa fa-plus icon-only"></i></a>
								<a href="#" class="btn btn-sm btn-danger <?= $count == 1 ? 'hide' : '' ?> del"><i class="fa fa-trash-o icon-only"></i></a>
							</div>
						</div>
						<?php endforeach; ?>
						<?php endif;?>
						</div>

						<div class="row">
							<div class="col-md-12">
									<button type="sumit" class="btn btn-success"><?= __('Lưu') ?></button>
							</div>
						</div>

						<?php if(!empty($contacts)):?>
						<div class="pr1 clearfix">
							<h4 class="mt20"><?= ('Danh sách thông tin')?></h4>
							<table class="table table-bordered table-hover" style="width:97.5%">
							<thead>
								<th style="width:70px;"><?= __('Thứ tự') ?></th>
								<th><?= __('Class') ?></th>
								<th><?= __('Tên') ?></th>
								<th><?= __('Nội dung') ?></th>
								<th width="15%"></th>
							</thead>
							<tbody>
							<?php foreach($contacts as $c):?>
							<tr id="<?= $c[$als]['id'] ?>" data-mode="contacts" data-action="edit" class="_item">
								<td align="center">
									<span data-field="sort" data-size="input-xsmall"><?= $c[$als]['sort'] ?></span>
								</td>
								<td>
									<span data-field="class" data-size="input-small"><?= $c[$als]['class'] ?></span>
								</td>
								<td>
									<span data-field="name" data-size="input-small"><?= $c[$als]['name'] ?></span>
								</td>
								<td>
									<span data-field="content" data-size="Large Input"><?= $c[$als]['content'] ?></span>
								</td>
								<td class="action" align="center">
									<a href="#" class="btn btn-xs btn-success edit"><?= __('sửa') ?></a>
									<a href="#" class="btn btn-xs btn-warning cancel" style="display:none"><?= __('Hủy') ?></a>
									<a href="#" class="btn btn-xs btn-danger delete"><?= __('Xóa') ?></a>
								</td>
							</tr>
							<?php endforeach; ?>
							</tbody>
							</table>
						</div>
						<?php endif; ?>
					</div>
				</div>
			</div>


		</div>
	</div>
</div>
<?php echo $this->Form->end( ); ?>
</div>

<!--<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>-->
<script src="<?= $this->webroot ?>assets/plugins/gmaps/mapAPI.js" type="text/javascript"></script>
<script src="<?= $this->webroot ?>assets/plugins/gmaps/gmaps.js" type="text/javascript"></script>

<script>
var map;
var lat = <?= $this->data['Map']['lat'];  ?>;
var lng = <?= $this->data['Map']['lng']; ?>;
var address = '<?= $this->data["Map"]["address"]; ?>';
</script>


